<template>
  <div>
    <zeda-dialog
      v-model="visible"
      width="1000px"
      title="采集记录详情"
      :before-close="handleClose"
    >
      <Title slot="green">
        <desc-base-info
          :data="info"
          :colnum-info="colnumInfo"
          align="right"
          :no-line-height="true"
          label-width="120px"
        ></desc-base-info>
        <el-divider></el-divider>
        <desc-base-info
          :data="info"
          :colnum-info="contrastInfo"
          align="right"
          :no-line-height="true"
          label-width="120px"
        ></desc-base-info>
        <desc-base-info
          :data="info"
          :colnum-info="baseInfo"
          align="right"
          :no-line-height="true"
          label-width="120px"
        ></desc-base-info>
      </Title>

      <form-button
        slot="footer"
        cancel-text="关闭"
        :show-submit-button="false"
        @cancel="handleClose"
      ></form-button>
    </zeda-dialog>
  </div>
</template>
<script>
import { getCollectdetail } from "@/api/sensingEquipment/index.js";
import FormButton from "@/components/FormButton";
import { dealElectricity, deepClone } from "@/utils/index";
export default {
  components: {
    FormButton,
  },
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: "" },
    modeldeviceCode: { type: [String, Number], default: "" },
  },
  data() {
    return {
      info: {},
      show: false,
    };
  },
  computed: {
    colnumInfo({ info }) {
      let arr = [];
      if (info.deviceModel == "3") {
        arr = [
          { label: "设备编号", prop: "deviceCode", colNum: 2 },
          { label: "物联网卡号", prop: "cardNum", colNum: 1 },
          { label: "电压", prop: "ua", colNum: 2, unit: "V" },
          { label: "电流", prop: "ia", colNum: 2, unit: "A" },
          { label: "有功功率", prop: "pa", colNum: 2, unit: "kw" },
          { label: "无功功率", prop: "qa", colNum: 2, unit: "kw" },
        ];
      } else {
        arr = [
          { label: "设备编号", prop: "deviceCode", colNum: 2 },
          { label: "物联网卡号", prop: "cardNum", colNum: 1 },
          { label: "A相电压", prop: "ua", colNum: 3, unit: "V" },
          { label: "B相电压", prop: "ub", colNum: 3, unit: "V" },
          { label: "C相电压", prop: "uc", colNum: 3, unit: "V" },
          { label: "A相电流", prop: "ia", colNum: 3, unit: "A" },
          { label: "B相电流", prop: "ib", colNum: 3, unit: "A" },
          { label: "C相电流", prop: "ic", colNum: 3, unit: "A" },
          { label: "AB相电压", prop: "uab", colNum: 3, unit: "V" },
          { label: "BC相电压", prop: "ubc", colNum: 3, unit: "V" },
          { label: "AC相电压", prop: "uac", colNum: 3, unit: "V" },
          { label: "A相有功功率", prop: "pa", colNum: 3, unit: "kw" },
          { label: "B相有功功率", prop: "pb", colNum: 3, unit: "kw" },
          { label: "C相有功功率", prop: "pc", colNum: 3, unit: "kw" },
          { label: "A相无功功率", prop: "qa", colNum: 3, unit: "kw" },
          { label: "B相无功功率", prop: "qb", colNum: 3, unit: "kw" },
          { label: "C相无功功率", prop: "qc", colNum: 3, unit: "kw" },
        ];
      }
      return arr;
    },
    contrastInfo({ info }) {
      return [
        { label: "电流变比CT", prop: "ct", colNum: 2 },
        { label: "电压变比PT", prop: "pt", colNum: 2 },
        { label: "尖峰用电量", prop: "spiksectionElectricity", colNum: 2 },
        { label: "高峰用电量", prop: "peaksectionElectricity", colNum: 2 },
        { label: "平段用电量", prop: "flatsectionElectricity", colNum: 2 },
        { label: "谷时用电量", prop: "valleysectionElectricity", colNum: 2 },
      ];
    },
    baseInfo({ info }) {
      return [
        { label: "设备回路状态", prop: "state", colNum: 2 },
        { label: "累计能耗", prop: "totalConsumption", colNum: 2, unit: "kwh" },
        {
          label: "日增能耗",
          prop: "dailyIncreaseConsumption",
          colNum: 2,
          unit: "kwh",
        },
        {
          label: "日增能耗同比",
          prop: "dailyIncreaseConsumptionRatio",
          colNum: 2,
          unit: "%",
        },
        {
          label: "月增能耗",
          prop: "monthlyIncreaseConsumption",
          colNum: 2,
          unit: "kwh",
        },
        {
          label: "月增能耗同比",
          prop: "monthlyIncreaseConsumptionRatio",
          colNum: 2,
          unit: "%",
        },
        {
          label: "季增能耗",
          prop: "quarterlyIncreaseConsumption",
          colNum: 2,
          unit: "kwh",
        },
        {
          label: "季增能耗同比",
          prop: "quarterlyIncreaseConsumptionRatio",
          colNum: 2,
          unit: "%",
        },
        {
          label: "年增能耗",
          prop: "annualIncreaseConsumption",
          colNum: 2,
          unit: "kwh",
        },
        {
          label: "年增能耗同比",
          prop: "annualIncreaseConsumptionRatio",
          colNum: 2,
          unit: "%",
        },
        { label: "维修次数", prop: "maintainNum", colNum: 2, unit: "次" },
        { label: "断电次数", prop: "outageNum", colNum: 2, unit: "次" },
        { label: "额定电流", prop: "ratedCurrent", colNum: 2, unit: "A" },
        {
          label: "当前日最高电流",
          prop: "dailyMaxCurrent",
          colNum: 2,
          unit: "A",
        },
      ];
    },
  },
  watch: {
    visible(value) {
      if (value) {
        this.getInfo();
      } else {
        this.model = {
          substation: "",
          identity: "",
          taxNum: "",
          code: "",
          switchStatus: "",
        };
      }
    },
  },
  methods: {
    getInfo() {
      let that = this;
      let query = {
        id: that.id,
        deviceCode: that.modeldeviceCode,
      };
      getCollectdetail(query)
        .then((res) => {
          if (res.code === 700) {
            that.$message.warning(res.msg);
            return false;
          }
          that.info = res?.data ?? {};
          // 数据处理
          this.info.ua = dealElectricity(this.info.ua);
          this.info.ub = dealElectricity(this.info.ub);
          this.info.ia = dealElectricity(this.info.ia, 1000, 3);
          this.info.uc = dealElectricity(this.info.uc);
          this.info.ib = dealElectricity(this.info.ib, 1000, 3);
          this.info.ic = dealElectricity(this.info.ic, 1000, 3);
          this.info.uab = dealElectricity(this.info.uab);
          this.info.ubc = dealElectricity(this.info.ubc);
          this.info.uac = dealElectricity(this.info.uac);
          this.info.pa = dealElectricity(this.info.pa, 1000, 3);
          this.info.pb = dealElectricity(this.info.pb, 1000, 3);
          this.info.pc = dealElectricity(this.info.pc, 1000, 3);
          this.info.qa = dealElectricity(this.info.qa, 1000, 3);
          this.info.qb = dealElectricity(this.info.qb, 1000, 3);
          this.info.qc = dealElectricity(this.info.qc, 1000, 3);
          this.info.dailyMaxCurrent = dealElectricity(
            this.info.dailyMaxCurrent,
            1000,
            3
          );
          this.info.spiksectionElectricity = dealElectricity(
            this.info.spiksectionElectricity
          );
          this.info.peaksectionElectricity = dealElectricity(
            this.info.peaksectionElectricity
          );
          this.info.flatsectionElectricity = dealElectricity(
            this.info.flatsectionElectricity
          );
          this.info.valleysectionElectricity = dealElectricity(
            this.info.valleysectionElectricity
          );
          this.info.totalConsumption = dealElectricity(
            this.info.totalConsumption
          );
          this.info.dailyIncreaseConsumption = dealElectricity(
            this.info.dailyIncreaseConsumption
          );
          this.info.monthlyIncreaseConsumption = dealElectricity(
            this.info.monthlyIncreaseConsumption
          );
          this.info.monthlyIncreaseConsumptionRatio = dealElectricity(
            this.info.monthlyIncreaseConsumptionRatio
          );
          this.info.quarterlyIncreaseConsumption = dealElectricity(
            this.info.quarterlyIncreaseConsumption
          );
          this.info.quarterlyIncreaseConsumptionRatio = dealElectricity(
            this.info.quarterlyIncreaseConsumptionRatio
          );
          this.info.annualIncreaseConsumption = dealElectricity(
            this.info.annualIncreaseConsumption
          );
          this.info.annualIncreaseConsumptionRatio = dealElectricity(
            this.info.annualIncreaseConsumptionRatio
          );
          this.info.ratedCurrent = dealElectricity(this.info.ratedCurrent);
        })
        .catch((err) => {
          that.info = {};
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
    handleClose(status) {
      this.$emit("close", typeof status === "boolean" ? status : false);
    },
  },
};
</script>
